<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>第一课</title>
    <style>
        .box {
            width: 400px;
            margin: 100px auto;
            padding: 15px;
            border: 1px solid #ddd;
            text-align: center;
        }

        .text {
            text-align: center;
            font-size: 28px;
            color: #333;
            display: inline-block;
            transition: color 0.5s;
            -moz-transition: all 0.5s;
            -webkit-transition: all 0.5s;
            -o-transition: all 0.5s;
        }

        .line {
            text-align: center;
            display: block;
            width: 0px;
            height: 4px;
            background: #0000ff;
            margin: 5px auto 0;
            transition: width 0.5s;
            -moz-transition: width 0.5s;
            -webkit-transition: width 0.5s;
            -o-transition: width 0.5s;
        }

        #btn {
            display: block;
            margin: 30px auto;
            font-size: 18px;
            font-weight: 500;
            padding: 6px 14px;
            border: 1px solid #ddd;
            border-radius: 10px;
            background: #fff;
            color: #000;
            outline: none;
        }
    </style>
</head>

<body>
    <div class="box">
        <h3 class="text default">前端学院
            <span class="line"></span>
        </h3>
        <button type="button" id="btn">切换样式</button>
    </div>
    <script>
        window.onload = function () {
            var flag = true;
            var button = document.getElementById("btn");
            var line = document.getElementsByClassName("line");
            var text = document.getElementsByClassName("text");
            button.addEventListener("click", function () {
                if (flag) {
                    line[0].style.width = "100%";
                    text[0].style.color = "#0000ff";
                    flag = false;
                } else {
                    line[0].style.width = "0";
                    text[0].style.color = "#333";
                    flag = true;
                }

            });
        }

    </script>
</body>

</html>